<?php

namespace App\Http\Controllers\Admin;


use App\Traits\User\TransactionTrait;
use Illuminate\Http\Request;

class TransactionController extends BaseController
{
    use TransactionTrait;

    /**
     * @param Request $request
     * @param \Illuminate\Contracts\Pagination\Paginator $items
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    protected function showTransactionsView(Request $request, $items)
    {
        $this->assign(array_merge([
            'subject' => '',
            'payer_name' => '',
            'payee_name' => '',
            'pay_state' => '',
            'min_amount' => '',
            'max_amount' => '',
            'pay_type' => '',
            'transaction_no' => '',
            'time_begin' => '',
            'time_end' => ''
        ], $request->all()));
        return $this->view('admin.transaction.transactions', [
            'items' => $items,
            'pagination' => $items->appends($request->except('page'))->render()
        ]);
    }

    /**
     *
     * @throws \Exception
     */
    public function index(Request $request)
    {
        return $this->showTransactions($request);
    }

    public function export()
    {


    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function batchDelete(Request $request)
    {
        $this->transactionRepository()->whereKey($request->input('items', []))->delete();
        return ajaxReturn();
    }
}
